package com.study.res.controller;

import com.study.res.comm.BaseResponse;
import com.study.res.enums.ErrorEnum;
import com.study.res.exception.WebException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName UnifyExceptionHandler
 * @Author swj
 * @Date 2020/10/10 10:32
 * controller层的异常统一处理类
 */
@ControllerAdvice
public class UnifyExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = WebException.class)
    public BaseResponse handleWebException(HttpServletRequest req, WebException e){
        return BaseResponse.retFail(ErrorEnum.SYSTEM_EXCEPTION,e);
    }

}
